﻿#include "formwindow.h"
#include "uimainwindow.h"
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QSpinBox>   //微调框
#include <QFileDialog>
FormWindow::FormWindow(QWidget *parent) : QWidget(parent)
{
   initWindow();
}

void FormWindow::initWindow()
{
    nameEdit = new QLineEdit;
    genderBox = new QComboBox;
    ageBox = new QSpinBox;
    QVBoxLayout *mainLayout= new QVBoxLayout(this);
    QFormLayout *fLayout = new QFormLayout;

    fLayout->addRow(new QLabel("姓名:"),nameEdit);
    fLayout->addRow("年龄:",ageBox);
//    QComboBox *cbox = new QComboBox;
    QStringList sl;
    sl<<"男"<<"女";
    genderBox->addItems(sl);
    fLayout->addRow("性别:",genderBox);

    mainLayout->addLayout(fLayout);
    commitButton = new QPushButton("提交");
    mainLayout->addWidget(commitButton);

    connect(commitButton,&QPushButton::clicked,this,&FormWindow::sendData);
}

void FormWindow::sendData()
{
    // 关闭窗口
    close();
    //获取数据
    QString name = nameEdit->text();
    int age = ageBox->value();
    QString gender = genderBox->currentText();

    Person p(name,age,gender);
    emit sendPerson(p);
    emit sendPerson(name,age,gender);
}
